using System;
using System.Text;

namespace ErrorDumper.Writing {
    public sealed class ConsoleExceptionWriter : IExceptionWriter {

        internal static string ToString(
            DateTimeOffset utc, ExceptionPropertyCollection properties, string content) {

            var builder = new StringBuilder("ErrorDump : " + utc.ToUniversalTime().ToString("s") + " : ");
            if (properties != null && properties.Count > 0)
                foreach (var h in properties)
                    builder.Append(h.Key + "=" + h.Value + "; ");
            builder.AppendLine();
            if (!string.IsNullOrWhiteSpace(content))
                builder.AppendLine(content);
            return builder.ToString();
        }

        public string WriteException(ExceptionPropertyCollection properties, string content) {
            var utc = DateTimeOffset.UtcNow;
            Console.Write(ToString(utc, properties, content));
            return "console:" + utc.ToString("s");
        }
    }
}